package com.lsl.legcommune.ui;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;
import android.widget.TextView;

public class MyCommuneFragment extends Fragment {
	
	private FragmentActivity activityContext;
	
	private MyCommuneAdapter adapter;
	private ViewPager pager;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {	
		super.onCreate(savedInstanceState);
		
		activityContext = getActivity();
		
		adapter = new MyCommuneAdapter(getChildFragmentManager());
		
	}
   
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.mycommune, container, false);       
               
        pager = (ViewPager)v.findViewById(R.id.pager);
    	pager.setAdapter(adapter);
        
        
        
        return v;
    }
    
    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
    	super.onViewCreated(view, savedInstanceState);
    	
    }
    
    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
    	// TODO Auto-generated method stub
    	super.onActivityCreated(savedInstanceState);        	
    }
        
    
    @Override
    public void onPause() {
    	// TODO Auto-generated method stub
    	super.onPause();
    }
    
    
    class MyCommuneAdapter extends FragmentStatePagerAdapter {

		public MyCommuneAdapter(FragmentManager fm) {
			super(fm);
			// TODO Auto-generated constructor stub
		}
		
		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return 2;
		}
		
		@Override
		public Fragment getItem(int position) {			
			return new MyCommuneGridFragment();
		}

    }
    
    class MyCommuneGridFragment extends Fragment {
    	
    	@Override
    	public View onCreateView(LayoutInflater inflater, ViewGroup container,
    			Bundle savedInstanceState) {
    		View v = inflater.inflate(R.layout.mycommune_gridview, container, false);       
    		GridView gv = (GridView)v.findViewById(R.id.mycommune_gridview);
    		gv.setAdapter(new MyCommuneGridAdapter(activityContext));
            return v;
    	}
    	
    }
	
}
